package com.snail.jj.androiddemos.bases;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.snail.jj.androiddemos.R;

/**
 * Created by snail on 2017/4/13.
 */

public class JavaActivity extends BaseActivity {

    public String BaseTag = "JavaActivity";
    private ListView aListView;
    private String[] dataSource = {
            "Interface",
            "Abstract",
            "Thread"
    };



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_java);
        initView();
    }

    public void initView() {
        setTitleBarTitle("Java基础");
        setRightViewVisiable(View.INVISIBLE);
        ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(JavaActivity.this,R.layout.support_simple_spinner_dropdown_item,dataSource);
        aListView = (ListView) findViewById(R.id.id_java_listView);
        aListView.setAdapter(adapter);
        aListView.setOnItemClickListener(
                new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        String className = "com.snail.jj.androiddemos.javabasic." + dataSource[position] + "Activity";
                        try {
                            Class<?> clazz = Class.forName(className);
                            BaseActivity activity = (BaseActivity) clazz.newInstance();
                            Intent intent = new Intent(JavaActivity.this,activity.getClass());
                            startActivity(intent);
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        } catch (InstantiationException e) {
                            e.printStackTrace();
                        }


                    }
                }
        );
    }

}
